var express = require("express");
var router = express.Router();
// var async = require("async");
const user_login = require("../model/user_login");
router.post("/api/v1/forgetPwd", function(req, res, next) {
  try {
    user_login.find({ phone: req.body.phone }, function(err, doc) {
      if (!err) {
        if (doc.length > 0) {
          user_login.update(
            {
              phone: req.body.phone
            },
            {
              $set: {
                password: req.body.password
              }
            },
            function(err, doc) {
              if (err) return next(err);
              res.jsonp({
                code: 200,
                data: doc,
                message: "修改成功"
              });
            }
          );
        } else {
          res.json({
            code: 201,
            message: "账号不存在"
          });
        }
      } else {
        return next(err);
      }
    });
  } catch (error) {
    res.status(500).send(error);
  }
});

// 导出模块（在 app.js 中引入）
module.exports = router;
